package com.jl.jlapp.mvp.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemChildClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.CompanyListAdapter;
import com.jl.jlapp.eneity.InvoiceUnitAndVatInvoiceAptitude;
import com.jl.jlapp.eneity.InvoiceUnitAndVatInvoiceAptitude.ResultDataBean;
import com.jl.jlapp.eneity.InvoiceUnitAndVatInvoiceAptitude.ResultDataBean.InvoiceUnitBean;
import com.jl.jlapp.eneity.InvoiceUnitAndVatInvoiceAptitude.ResultDataBean.VatInvoiceAptitudeBean;
import com.jl.jlapp.eneity.PostModel;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.nets.Transformer;
import com.jl.jlapp.popu.InvoiceAndCouponPromptPopu;
import com.jl.jlapp.utils.CustomLanearLayoutManager;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

public class OrderWriteActivity extends AppCompatActivity {
    public static int index = 0;
    @BindView(R.id.add_taxpayer_identification_number_world_rela)
    RelativeLayout addTaxpayerIdentificationNumberWorldRela;
    @BindView(R.id.add_unit_name_world_rela)
    RelativeLayout addUnitNameWorldRela;
    @BindView(R.id.bank_account)
    TextView bankAccount;
    int chooseInvoiceContentDetail = 1;
    int chooseInvoiceLookedUpType = 1;
    int chooseInvoiceType = 2;
    @BindView(R.id.deposit_bank)
    TextView depositBank;
    @BindView(R.id.edit_taxpayer_identification_number)
    TextView editTaxpayerIdentificationNumber;
    @BindView(R.id.edit_unit_name)
    TextView editUnitName;
    private InvoiceAndCouponPromptPopu invoiceAndCouponPromptPopu;
    @BindView(R.id.invoice_content_rela)
    RelativeLayout invoiceContentRela;
    @BindView(R.id.invoice_looked_up_type)
    RelativeLayout invoiceLookedUpType;
    @BindView(R.id.invoice_must_know_message)
    TextView invoiceMustKnowMessage;
    private List<InvoiceUnitAndVatInvoiceAptitude.ResultDataBean.InvoiceUnitBean> invoiceUnitBeans;
    private CompanyListAdapter listAdapter;
    @BindView(R.id.rb_added_invoice)
    RadioButton rbAddedInvoice;
    @BindView(R.id.rb_company)
    RadioButton rbCompany;
    @BindView(R.id.rb_detailed)
    RadioButton rbDetailed;
    @BindView(R.id.rb_foods)
    RadioButton rbFoods;
    @BindView(R.id.rb_no_invoice)
    RadioButton rbNoInvoice;
    @BindView(R.id.rb_ordinary_invoice)
    RadioButton rbOrdinaryInvoice;
    @BindView(R.id.rb_personal)
    RadioButton rbPersonal;
    @BindView(R.id.registered_address)
    TextView registeredAddress;
    @BindView(R.id.registered_tel)
    TextView registeredTel;
    InvoiceUnitAndVatInvoiceAptitude.ResultDataBean resultDataBean;
    @BindView(R.id.rl_second)
    RelativeLayout rlSecond;
    @BindView(R.id.rl_second_no_vate_invoice)
    RelativeLayout rlSecondNoVateInvoice;
    @BindView(R.id.rl_second_no_vate_invoice_text)
    TextView rlSecondNoVateInvoiceText;
    @BindView(R.id.rl_second_vate_invoice_msg)
    RelativeLayout rlSecondVateInvoiceMsg;
    @BindView(R.id.rlv_company_list)
    RecyclerView rlvCompanyList;
    @BindView(R.id.taxpayer_identification_number)
    TextView taxpayerIdentificationNumber;
    @BindView(R.id.tv_add_company)
    TextView tvAddCompany;
    @BindView(R.id.tv_save_company)
    TextView tvSaveCompany;
    int userId = 0;
    private InvoiceUnitAndVatInvoiceAptitude.ResultDataBean.VatInvoiceAptitudeBean vatInvoiceAptitudeBean;
    @BindView(R.id.vat_invoice_unit_content)
    TextView vatInvoiceUnitContent;

    private void initView(InvoiceUnitAndVatInvoiceAptitude.ResultDataBean paramResultDataBean) {
        if (this.invoiceUnitBeans == null) {
            this.invoiceUnitBeans = new ArrayList();
        }
        this.invoiceUnitBeans.clear();
        int i = 0;
        while (i < paramResultDataBean.getInvoiceUnit().size()) {
            this.invoiceUnitBeans.add(paramResultDataBean.getInvoiceUnit().get(i));
            i += 1;
        }
        if (this.listAdapter == null) {
            this.listAdapter = new CompanyListAdapter(R.layout.item_company_list, this.invoiceUnitBeans);
            CustomLanearLayoutManager customLanearLayoutManager = new CustomLanearLayoutManager(this);
            customLanearLayoutManager.setScrollEnabled(false);
            this.rlvCompanyList.setLayoutManager(customLanearLayoutManager);
            this.rlvCompanyList.setAdapter(this.listAdapter);
            this.listAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
                public void onItemChildClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                    OrderWriteActivity.index = paramAnonymousInt;
                    OrderWriteActivity.this.listAdapter.notifyDataSetChanged();
                }
            });
            return;
        }
        this.listAdapter.notifyDataSetChanged();
    }

    private void setDataTovatInvoiceAptitudeControl(InvoiceUnitAndVatInvoiceAptitude.ResultDataBean.VatInvoiceAptitudeBean paramVatInvoiceAptitudeBean) {
        if (paramVatInvoiceAptitudeBean.getState() == 2) {
            this.vatInvoiceUnitContent.setText(paramVatInvoiceAptitudeBean.getUnitName());
            this.taxpayerIdentificationNumber.setText(paramVatInvoiceAptitudeBean.getTaxpayerIdentificationNumber());
            this.registeredAddress.setText(paramVatInvoiceAptitudeBean.getRegisteredAddress());
            this.registeredTel.setText(paramVatInvoiceAptitudeBean.getRegisteredTel());
            this.depositBank.setText(paramVatInvoiceAptitudeBean.getDepositBank());
            this.bankAccount.setText(paramVatInvoiceAptitudeBean.getBankAccount());
        }
    }

    public void addInvoiceUnit(String paramString1, String paramString2, int paramInt) {
        Net.get().addInvoiceUnit(paramString1, paramString2, paramInt)
                .compose(Transformer.<PostModel>switchSchedulers())
                .subscribe(new CommonObserver<PostModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(PostModel postModel) {

                    }
                });
    }

    public void getInvoiceUnitAndVatInvoiceAptitudeByUserId(Integer paramInteger) {
        Net.get().getInvoiceUnitAndVatInvoiceAptitudeByUserId(paramInteger.intValue())
                .compose(Transformer.<InvoiceUnitAndVatInvoiceAptitude>switchSchedulers())
                .subscribe(new CommonObserver<InvoiceUnitAndVatInvoiceAptitude>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(InvoiceUnitAndVatInvoiceAptitude invoiceUnitAndVatInvoiceAptitude) {

                    }
                });
    }

    @OnClick({R.id.rb_ordinary_invoice, R.id.rb_added_invoice, R.id.rb_no_invoice, R.id.rb_personal, R.id.rb_company, R.id.return_btn, R.id.tv_add_company, R.id.tv_save_company, R.id.btn_ok, R.id.rb_detailed, R.id.rb_foods, R.id.invoice_must_know_message})
    public void onClick(View paramView) {
        switch (paramView.getId()) {
            case R.id.rb_ordinary_invoice:
                this.chooseInvoiceType = 0;
                this.rbOrdinaryInvoice.setTextColor(getResources().getColor(R.color.checkGreenColor));
                this.rbAddedInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                this.rbNoInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                this.invoiceLookedUpType.setVisibility(View.VISIBLE);
                this.rlSecondVateInvoiceMsg.setVisibility(View.GONE);
                this.rlSecond.setVisibility(View.VISIBLE);
                this.invoiceContentRela.setVisibility(View.VISIBLE);
                this.rlSecondNoVateInvoice.setVisibility(View.GONE);
                break;
            case R.id.rb_added_invoice:
                this.chooseInvoiceType = 1;
                this.rbOrdinaryInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                this.rbAddedInvoice.setTextColor(getResources().getColor(R.color.checkGreenColor));
                this.rbNoInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                if (this.vatInvoiceAptitudeBean != null) {
                    if (this.vatInvoiceAptitudeBean.getState() == 2) {
                        this.invoiceLookedUpType.setVisibility(View.GONE);
                        this.rlSecondVateInvoiceMsg.setVisibility(View.VISIBLE);
                        this.rlSecond.setVisibility(View.VISIBLE);
                        this.invoiceContentRela.setVisibility(View.VISIBLE);
                        this.rlSecondNoVateInvoice.setVisibility(View.GONE);
                        return;
                    }
                    if (this.vatInvoiceAptitudeBean.getState() == 1) {
                        this.rlSecondNoVateInvoice.setVisibility(View.VISIBLE);
                        this.invoiceLookedUpType.setVisibility(View.GONE);
                        this.rlSecondVateInvoiceMsg.setVisibility(View.GONE);
                        this.rlSecond.setVisibility(View.VISIBLE);
                        this.invoiceContentRela.setVisibility(View.GONE);
                        this.rlSecondNoVateInvoiceText.setText("增票资质审核未通过");
                        return;
                    }
                    this.rlSecondNoVateInvoice.setVisibility(View.VISIBLE);
                    this.invoiceLookedUpType.setVisibility(View.GONE);
                    this.rlSecondVateInvoiceMsg.setVisibility(View.GONE);
                    this.rlSecond.setVisibility(View.VISIBLE);
                    this.invoiceContentRela.setVisibility(View.GONE);
                    this.rlSecondNoVateInvoiceText.setText("增票资质审核中");
                    return;
                }
                this.rlSecondNoVateInvoice.setVisibility(View.VISIBLE);
                this.invoiceLookedUpType.setVisibility(View.GONE);
                this.rlSecondVateInvoiceMsg.setVisibility(View.GONE);
                this.rlSecond.setVisibility(View.VISIBLE);
                this.invoiceContentRela.setVisibility(View.GONE);
                break;
            case R.id.rb_no_invoice:
                this.chooseInvoiceType = 2;
                this.rbOrdinaryInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                this.rbAddedInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                this.rbNoInvoice.setTextColor(getResources().getColor(R.color.checkGreenColor));
                this.rlSecond.setVisibility(View.GONE);
                this.invoiceContentRela.setVisibility(View.GONE);
                break;
            case R.id.rb_personal:
                this.chooseInvoiceLookedUpType = 1;
                this.tvAddCompany.setVisibility(View.GONE);
                this.rlvCompanyList.setVisibility(View.GONE);
                this.addUnitNameWorldRela.setVisibility(View.GONE);
                this.addTaxpayerIdentificationNumberWorldRela.setVisibility(View.GONE);
                this.tvSaveCompany.setVisibility(View.GONE);
                this.tvAddCompany.setVisibility(View.GONE);
                break;
            case R.id.rb_company:
                this.chooseInvoiceLookedUpType = 0;
                this.addUnitNameWorldRela.setVisibility(View.GONE);
                this.addTaxpayerIdentificationNumberWorldRela.setVisibility(View.GONE);
                this.tvSaveCompany.setVisibility(View.GONE);
                this.tvAddCompany.setVisibility(View.VISIBLE);
                if (this.invoiceUnitBeans.size() > 0) {
                    this.tvAddCompany.setVisibility(View.VISIBLE);
                    this.rlvCompanyList.setVisibility(View.VISIBLE);
                    return;
                }
                this.addUnitNameWorldRela.setVisibility(View.VISIBLE);
                this.addTaxpayerIdentificationNumberWorldRela.setVisibility(View.VISIBLE);
                this.tvSaveCompany.setVisibility(View.VISIBLE);
                this.tvAddCompany.setVisibility(View.GONE);
                break;
            case R.id.tv_add_company:
                this.addUnitNameWorldRela.setVisibility(View.VISIBLE);
                this.addTaxpayerIdentificationNumberWorldRela.setVisibility(View.VISIBLE);
                this.tvSaveCompany.setVisibility(View.VISIBLE);
                this.tvAddCompany.setVisibility(View.GONE);
                break;
            case R.id.tv_save_company:
                String unitname = this.editUnitName.getText().toString().trim();
                String str = this.editTaxpayerIdentificationNumber.getText().toString().trim();
                if ("".equals(unitname)) {
                    Toast.makeText(this, "单位名称不能为空!", Toast.LENGTH_SHORT).show();
                    return;
                }
                if ("".equals(str)) {
                    Toast.makeText(this, "纳税人识别号不能为空!", Toast.LENGTH_SHORT).show();
                    return;
                }
                addInvoiceUnit(unitname, str, this.userId);
                return;
            case R.id.rb_detailed:
                this.chooseInvoiceContentDetail = 1;
                return;
            case R.id.rb_foods:
                this.chooseInvoiceContentDetail = 0;
                return;
            case R.id.btn_ok:
                Intent intent = new Intent();
                intent.putExtra("chooseInvoiceType", this.chooseInvoiceType);
                if (this.chooseInvoiceType == 0) {
                    intent.putExtra("chooseInvoiceLookedUpType", this.chooseInvoiceLookedUpType);
                    intent.putExtra("chooseInvoiceContentDetail", this.chooseInvoiceContentDetail);
                    if (this.chooseInvoiceLookedUpType == 0) {
                        if (this.invoiceUnitBeans.size() <= 0) {
                            return;
                        }
                        intent.putExtra("unitName", ((InvoiceUnitAndVatInvoiceAptitude.ResultDataBean.InvoiceUnitBean) this.invoiceUnitBeans.get(index)).getUnitName());
                        intent.putExtra("taxpayerIdentificationNumber", ((InvoiceUnitAndVatInvoiceAptitude.ResultDataBean.InvoiceUnitBean) this.invoiceUnitBeans.get(index)).getTaxpayerIdentificationNumber());
                    }
                } else {
                    setResult(2, intent);
                    finish();
                    Toast.makeText(this, "暂无单位信息，请添加后再点击确认!", Toast.LENGTH_SHORT).show();
                    if (this.chooseInvoiceType == 1) {
                        intent.putExtra("chooseInvoiceContentDetail", this.chooseInvoiceContentDetail);
                        if (this.vatInvoiceAptitudeBean == null) {
                            return;
                        }
                        if (this.vatInvoiceAptitudeBean.getState() != 2) {
                            break;
                        }
                        intent.putExtra("unitName", this.vatInvoiceAptitudeBean.getUnitName());
                        intent.putExtra("taxpayerIdentificationNumber", this.vatInvoiceAptitudeBean.getTaxpayerIdentificationNumber());
                        intent.putExtra("registeredAddress", this.vatInvoiceAptitudeBean.getRegisteredAddress());
                        intent.putExtra("registeredTel", this.vatInvoiceAptitudeBean.getRegisteredTel());
                        intent.putExtra("depositBank", this.vatInvoiceAptitudeBean.getDepositBank());
                        intent.putExtra("bankAccount", this.vatInvoiceAptitudeBean.getBankAccount());
                        intent.putExtra("businessLicenseUrl", this.vatInvoiceAptitudeBean.getBusinessLicenseUrl());
                    }
                }
                if (this.vatInvoiceAptitudeBean.getState() == 0) {
                    Toast.makeText(this, "增票信息审核中，请耐心等待!", Toast.LENGTH_SHORT).show();
                    return;
                }
                Toast.makeText(this, "增票信息审核未通过，请到个人中心进行修改!", Toast.LENGTH_SHORT).show();
                Toast.makeText(this, "暂无增票信息，请到个人中心进行添加!", Toast.LENGTH_SHORT).show();
                return;
            case R.id.invoice_must_know_message:
                this.invoiceAndCouponPromptPopu = new InvoiceAndCouponPromptPopu(this, 0);
                this.invoiceAndCouponPromptPopu.showAtLocation(findViewById(R.id.invoice_page), 17, 0, 0);
                return;
        }
        finish();
    }

    protected void onCreate(@Nullable Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_order_write);
        ButterKnife.bind(this);
    }

    protected void onResume() {
        super.onResume();
        this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", 0);
        if (this.userId > 0) {
            Intent localIntent = getIntent();
            this.chooseInvoiceType = localIntent.getIntExtra("chooseInvoiceType", 2);
            if (this.chooseInvoiceType == 0) {
                this.rbOrdinaryInvoice.setTextColor(getResources().getColor(R.color.checkGreenColor));
                this.rbAddedInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                this.rbNoInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                this.chooseInvoiceLookedUpType = localIntent.getIntExtra("chooseInvoiceLookedUpType", 1);
                this.chooseInvoiceContentDetail = localIntent.getIntExtra("chooseInvoiceContentDetail", 1);
                if (this.chooseInvoiceLookedUpType == 1) {
                    this.rbPersonal.setChecked(true);
                    if (this.chooseInvoiceContentDetail != 1) {
                        return;
                    }
                    this.rbDetailed.setChecked(true);
                }
            } else {
                getInvoiceUnitAndVatInvoiceAptitudeByUserId(Integer.valueOf(this.userId));
                this.rbCompany.setChecked(true);
                this.tvAddCompany.setVisibility(View.VISIBLE);
                this.rlvCompanyList.setVisibility(View.VISIBLE);
                this.rbFoods.setChecked(true);
                if (this.chooseInvoiceType == 1) {
                    this.chooseInvoiceContentDetail = localIntent.getIntExtra("chooseInvoiceContentDetail", 1);
                    if (this.chooseInvoiceContentDetail == 1) {
                        this.rbDetailed.setChecked(true);
                    } else {
                        this.rbAddedInvoice.setChecked(true);
                        this.rbOrdinaryInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                        this.rbAddedInvoice.setTextColor(getResources().getColor(R.color.checkGreenColor));
                        this.rbNoInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                        this.invoiceLookedUpType.setVisibility(View.GONE);
                        this.rlSecondVateInvoiceMsg.setVisibility(View.VISIBLE);
                        this.rlSecond.setVisibility(View.VISIBLE);
                        this.invoiceContentRela.setVisibility(View.VISIBLE);
                        this.rlSecondNoVateInvoice.setVisibility(View.GONE);
                        this.rbFoods.setChecked(true);
                    }
                }
                this.rbNoInvoice.setChecked(true);
                this.rbOrdinaryInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                this.rbAddedInvoice.setTextColor(getResources().getColor(R.color.trans_333333));
                this.rbNoInvoice.setTextColor(getResources().getColor(R.color.checkGreenColor));
                this.rlSecond.setVisibility(View.GONE);
                this.invoiceContentRela.setVisibility(View.GONE);
            }
        }
        Toast.makeText(this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(this, LoginActivity.class));
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/OrderWriteActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */